#region Using References

using System;

#endregion

namespace Beaker.OpenCube.Game.Converters
{
	/// <summary>
	/// Extensions that add methods to TimeSpan for easy conversion.
	/// </summary>
	public static class TimeSpanExtensions
	{
		/// <summary>
		/// Get the number of game ticks from the TimeSpan
		/// </summary>
		/// <param name="timeSpan">The time span to get the number of game ticks from.</param>
		/// <returns>The number of game ticks.</returns>
		public static long ToGameTicks( this TimeSpan timeSpan )
		{
			return timeSpan.Ticks / GameTicksTimeSpanConverter.TickMultiplier;
		}

		/// <summary>
		/// Adds the give number of game ticks to the TimeSpan.
		/// </summary>
		/// <param name="timeSpan">The time span to add the ticks to.</param>
		/// <param name="ticks">The number of ticks to add.</param>
		/// <returns>The resulting <see cref="TimeSpan"/> after adding the game ticks.</returns>
		public static TimeSpan AddGameTicks( this TimeSpan timeSpan, long ticks )
		{
			return new TimeSpan( timeSpan.Ticks + ( ticks * GameTicksTimeSpanConverter.TickMultiplier ) );
		}

		/// <summary>
		/// Subtrackts the given number of game ticks from the TimeSpan.
		/// </summary>
		/// <param name="timeSpan">The time span to subtract the ticks from.</param>
		/// <param name="ticks">The number of ticks to subtract.</param>
		/// <returns>The resulting <see cref="TimeSpan"/> after subtracting the game ticks.</returns>
		public static TimeSpan SubtracktGameTicks( this TimeSpan timeSpan, long ticks )
		{
			return new TimeSpan( timeSpan.Ticks - ( ticks * GameTicksTimeSpanConverter.TickMultiplier ) );
		}

		/// <summary>
		/// Create a timespan from the given number of game ticks.
		/// </summary>
		/// <param name="ticks">The number of ticks to convert to a time span.</param>
		/// <returns>A time span equalling the same duration as the number of game ticks.</returns>
		public static TimeSpan FromGameTicks( long ticks )
		{
			return new TimeSpan( ticks * GameTicksTimeSpanConverter.TickMultiplier );
		}
	}
}